package de.jmda.util.gui.swing;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;

import javax.annotation.processing.Processor;

import org.junit.Test;

import de.jmda.gui.swing.mvc.ControllerSupportEnabledProcessor;
import de.jmda.mproc.JUTProcessor;
import de.jmda.mproc.LaunchConfigurationBuilder;
import de.jmda.mproc.LaunchConfigurationBuilderData;
import de.jmda.mproc.Launcher;
import de.jmda.util.fileset.FileSet.RuleSetUpdateMode;

public class JUTControllerSupportEnabledProcessorJV6 extends JUTProcessor
{
	@Test
	public void testProcessor()
	{
		Class<? extends Processor> processorClass =
				ControllerSupportEnabledProcessor.class;
		
		LaunchConfigurationBuilderData launchConfigurationBuilderData =
				new LaunchConfigurationBuilderData();
		
		launchConfigurationBuilderData.fileSetJavaSources.includeFile(
				new File(
						"./../jmda.core.jv6/src/main/java/" +
								JPanelFavourites.class.getName().replace('.', '/') +
								".java"),
						RuleSetUpdateMode.ADD_RULE);
		
		launchConfigurationBuilderData.processorClasses.add(processorClass);
		
		try
    {
	    launchConfiguration =
	    		LaunchConfigurationBuilder.build(launchConfigurationBuilderData);
    }
    catch (InstantiationException e)
    {
    	fail("failure building launch configruration\n" + e);
    }
    catch (IllegalAccessException e)
    {
    	fail("failure building launch configruration\n" + e);
    }

		try
    {
	    assertTrue(
	    		"unexpected return value for launch of " +
	    		processorClass.getName(),
	    		Launcher.launch(launchConfiguration));
    }
    catch (IOException e)
    {
    	fail(
    			"failure launching annotation processor [" +
    			processorClass.getName() + "]\n" + e);
    }
	}
}